package com.ruimei.util;

import com.alibaba.fastjson.JSON;
import com.ruimei.entitys.PermissVo;
import com.ruimei.entitys.Teacher;
import com.ruimei.mapper.AttendanceMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * 判断教师权限 是否查看所有班级*/
public class postUtil {

    public static Boolean post(RedisTemplate<String,String> redisTemplate,String teacherId,AttendanceMapper mapper){
        boolean post = false;
        List<String> list= mapper.getPostId(teacherId);
        PermissVo permiss;
        if(list.size() != 0){
            breakTo:
            for (String item : list){
        System.out.println(item);
                permiss= JSON.parseObject(redisTemplate.opsForValue().get("post_" + item), PermissVo.class);
                if(permiss != null){
                    for (String i : permiss.getAllCheckedKeys()) {
                        if ("e7fa2b1f8cc411e997fd00163e1d6427".equals(i)) {
                            post = true;  //如果有班级设置权限  则设置权限为true
                            break breakTo;
                        } else {
                            continue;
                        }
                    }
                }
            }
        }
        System.out.println(post);
        return post;
    }
}
